package com.zslin.business.tools.excel;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;

@RestController
@RequestMapping(value = "api/downloadOrders")
public class DownloadOrdersController {

    @Autowired
    private ExcelExportUtil excelExportUtil;

    @GetMapping(value = {"", "/", "index"})
    public void index(String day, HttpServletResponse response) {
        try {
            response.setContentType("application/vnd.ms-excel"); // 设置返回内容格式
            OutputStream os = response.getOutputStream();
            response.setHeader("Content-Disposition", "attachment; filename=Orders-" + day+".xlsx");
            excelExportUtil.export2Response(os, day);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
